package temporay;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;

/**
 * program: io-share 
 * author: bsworld.xie 
 * create: 2021-04-20 14:59 
 * description: 
 */
public abstract class AbstractSelectThread extends Thread{

    protected final Selector selector;

    public AbstractSelectThread(String name) throws IOException {
        super(name);
        this.selector = Selector.open();
    }

    public void wakeupSelector() {
        selector.wakeup();
    }


    public void cleanupSelectionKey(SelectionKey key) {
        if (key != null) {
            try {
                key.cancel();
            } catch (Exception ex) {
                System.out.println("ignoring exception during selectionkey cancel" + ex);
            }
        }


    }
}